# coding:utf8
# 数学 - 工具类

import random
from datetime import datetime,timezone,timedelta
import time
from AnalysisService import MMKeyUtil

'''
    时间
'''


class TimeFormatUtil:

    @staticmethod
    def time():
        return time.time()

    '''
        返回 当前 时间格式
    '''
    @staticmethod
    def formatToStr():
        currentTime = int(time.time())
        format = time.strftime(MMKeyUtil.DATE_FORAMT, time.localtime(currentTime))
        return format

    '''
        返回 当前 时间格式
    '''
    @staticmethod
    def format():
        currentTime = int(time.time())
        format = time.strftime(MMKeyUtil.DATE_FORAMT, time.localtime(currentTime))
        return format

    '''
        返回 时间格式
    '''
    @staticmethod
    def formatFromTimestamp(timestamp):
        currentTime = int(timestamp)
        format = time.strftime(MMKeyUtil.DATE_FORAMT, time.localtime(currentTime))
        return format

    '''
        返回 随机 时间格式
    '''
    @staticmethod
    def random():
        randomTime = random.randint(1541007640, 1543552840)
        # print('randomTime: ',time.localtime(randomTime))
        format = time.strftime(MMKeyUtil.DATE_FORAMT, time.localtime(randomTime))
        return format


class DateFormatUtil:

    @staticmethod
    def timestamp():
        return datetime.now().timestamp()

    '''
        返回 当前 时间格式
    '''

    @staticmethod
    def format():
        # date_now = datetime.now()
        utc_dt = datetime.utcnow().replace(tzinfo=timezone.utc)
        print(utc_dt)
        date_now = utc_dt.astimezone(timezone(timedelta(hours=8)))
        return datetime.strftime(date_now, MMKeyUtil.DATE_FORAMT)

    @staticmethod
    def formatToToday():
        timestamp = datetime.now()
        return datetime.strftime(timestamp, MMKeyUtil.DAY_FORAMT)

    @staticmethod
    def formatToMonth():
        timestamp = datetime.now()
        return datetime.strftime(timestamp, MMKeyUtil.MONTH_FORAMT)


    @staticmethod
    def formatToStr(timestamp):
        return datetime.strftime(timestamp, MMKeyUtil.DATE_FORAMT)

    '''
        返回 时间戳
    '''
    @staticmethod
    def toTimestamp(time):

        date_time = datetime.strptime(time, MMKeyUtil.DATE_FORAMT)
        # date_time.timestamp()
        # time_time = time.mktime(date_time.timetuple())
        timeStamp = int(date_time.timestamp())
        return timeStamp

